package club.sh.generator.utils;

import org.springframework.util.ResourceUtils;

import java.io.*;

/**
 * txt打印
 * @author 林思浩
 * @date 2020/07/24 14:22
 */
public class TxtUtil {

    public static void printBanner() {
        try {
            String banner = readTxt(ResourceUtils.getFile("classpath:banner.txt"));
            System.out.println(banner);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * 读取txt
     * @param file
     * @return
     */
    private static String readTxt(File file) {
        InputStreamReader in = null;
        BufferedReader br = null;
        try {
            in = new InputStreamReader(new FileInputStream(file), "UTF-8");
            br = new BufferedReader(in);
            StringBuffer sb = new StringBuffer();
            String temp = null;
            while ((temp = br.readLine()) != null) {
                sb.append(temp + "\n");
            }
            return sb.toString();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                br.close();
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        return null;
    }

}